<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单页面</title>
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layui-tab">
    <ul class="layui-tab-title">
        <li class="layui-this">全部订单</li>
    </ul>
    <fieldset class="table-search-fieldset">
        <legend>搜索信息</legend>
        <div style="margin: 10px 10px 10px 10px">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">订单号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" autocomplete="off" class="layui-input" placeholder="请输入订单号">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-bg-red" lay-submit lay-filter="data-search-btn">搜 索</button>

                    </div>
                </div>
            </form>
        </div>
    </fieldset>

    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    <script type="text/html" id="currentTableBar">
        <a class="layui-btn  layui-btn-xs " lay-event="findOne">查看详情</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除订单</a>
    </script>

</div>

<script type="text/html" id="increment">
    {{d.LAY_TABLE_INDEX+1}}
</script>

<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;

        laydate.render({
            elem: '#grade',
            type: 'year'
        });



        table.render({
            elem: '#currentTableId',
            url: '${pageContext.request.contextPath}/orderServlet?method=findAll',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],


            cols: [[
                {type: "checkbox", width: 50},
                {field: 'increment', width: 80, title: '序号', sort: true,templet:'#increment'},
                {field: 'order_image_url', width: 130,title: '商品图片',templet: function(d) {
                        return '<img src="${pageContext.request.contextPath}/' + d.order_image_url + '" style="width: 50%; height: 100%;">';
                    }  },
                {field: 'orderId', width: 130, title: '订单序号'},
                {field: 'orderName', width: 120, title: '商品名称'},
                {field: 'orderType', width: 130, title: '商品类型'},,
                {field: 'orderTime', width: 130,title: '购买时间' },
                {field: 'orderPrice', width: 130, title: '订单价格'},
                {field: 'orderStatus', width: 140, title: '订单状态', sort: true},
                {fixed:'right',title: '操作', minWidth: 230, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var searchParams = {};
            if (data.field.orderId) {
                searchParams.orderId = data.field.orderId;
            }

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                },
                where: searchParams
            }, 'data');

            return false;
        });

        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log('orderId:'+data.orderId);
            if(obj.event === 'findOne'){
                var index = layer.open({
                    title: '订单详情',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['60%', '75%'],
                    content: '${pageContext.request.contextPath}/orderServlet?method=findById&orderId='+data.orderId,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }  else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    $.get('${pageContext.request.contextPath}/orderServlet?method=removeById',{"orderId":data.orderId},function (data){
                        if(data == 1){
                            layer.msg('删除成功',{icon:1});
                            // 表格重新加载
                            table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                }
                            )
                        }else{
                            layer.msg('删除失败',{icon:2});
                        }
                    },'json');

                    layer.close(index);
                });
            }
        });

    });
</script>
</body>
</html>
